package com.devin.dao;

import com.devin.pojo.LogInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.cache.decorators.LruCache;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
@CacheNamespace(blocking = true,eviction = LruCache.class,flushInterval = 0L,size=1024,readWrite = true)
public interface LogMapper {
    @Select("select * from logs")
    @Results({/*@Result(id = true,property = "id",column = "id"),*/
            /*@Result(property = "username",column = "username"),
            @Result(property = "visitTime",column = "visitTime"),
            @Result(property = "ip",column = "ip"),
            @Result(property = "method",column = "method"),
            @Result(property = "url",column = "url"),
            @Result(property = "duration",column = "duration"),*/
            @Result(property = "visitTime",column = "visitTime"
                    ,jdbcType = JdbcType.VARCHAR
                    ,typeHandler = com.devin.dao.typeHandlers.Date2DateTimeTypeHandler.class)})
    @Options(useCache = true)
    List<LogInfo> getLogs();

    @Delete("delete from logs where id=#{logId}")
    void delLog(Integer logId);

    @Insert("insert into logs values(null,#{username},#{visitTime},#{ip},#{method},#{url},#{duration})")
    void saveLog(LogInfo logInfo);
}
